import { MyWsErrorResponse, OnlineUserItem, UserInfo } from "src/common/model";
import { RoleEntity, UserEntity } from "src/entity";
import type { Systeminformation } from "systeminformation";

export enum WsEvent {
    EXCEPTION = "exception",
    BROADCAST_RUN_STATUS_INFO = "broadcast_run_status_info",

    REFRESH_USER_STATUS = "refresh_user_status",

    // 后台
    BROADCAST_ONLINE_USER = "broadcast_online_user",
    BROADCAST_USER_STATUS = "broadcast_user_status",
    BACKGROUND_KICK_USER = "background_kick_user",
}

// event 返回数据结构 预览

export interface WsEventResponse {
    [WsEvent.EXCEPTION]: MyWsErrorResponse;

    [WsEvent.BROADCAST_RUN_STATUS_INFO]: {
        type: "cpu_usage";
        data: Systeminformation.CurrentLoadData;
    } & {
        type: "memory";
        data: Systeminformation.MemData;
    } & {
        type: "processes";
        data: Systeminformation.ProcessesData;
    };

    [WsEvent.REFRESH_USER_STATUS]: void;

    [WsEvent.BROADCAST_ONLINE_USER]: Record<OnlineUserItem["id"], OnlineUserItem>;
    [WsEvent.BROADCAST_USER_STATUS]:
        | {
              type: "update.user";
              data: UserEntity[];
          }
        | {
              type: "remove.user";
              data: number[];
          }
        | {
              type: "update.role";
              data: RoleEntity[];
          }
        | {
              type: "remove.role";
              data: number[];
          };
    [WsEvent.BACKGROUND_KICK_USER]: void;
}
